package com.itheima.chapter09.io.charstream;

import java.io.*;
import java.util.Arrays;

//字符缓冲流操作文件中数据顺序
public class Caes2 {
    public static void main(String[] args) throws IOException {
        //1.把文件中数据读进来
        BufferedReader br =new BufferedReader(new FileReader("MyIdeaTest\\e.txt"));
        String line = br.readLine();
        System.out.println(line);
        //2.按照空格切割
        String[] split = line.split(" ");
        //3.把字符串类型数组变成int类型数组
        int[]  arr =new int[split.length];
        for (int i = 0; i < split.length; i++) {
            int parseInt = Integer.parseInt(split[i]);
            arr[i] =parseInt;
        }
        //4.排序
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        //5.把排序之后的结果写回本地
        BufferedWriter bw =new BufferedWriter(new FileWriter("MyIdeaTest\\e.txt"));
        for (int i = 0; i < arr.length; i++) {
            bw.write(arr[i]+" ");
            bw.flush();
        }
        br.close();
        bw.close();
        //
    }
}
